package red.book._1._1;

/**
 * 最简单的定容栈，底层使用数组
 */
public class Demo3 {

    public static int rank(int key, int[] arrs, int lo, int hi){
        if (lo > hi){
            return -1;
        }
        int mid = (lo + hi) / 2;
        if (arrs[mid] < key){
            return rank(key, arrs, mid+1, hi);
        }else if (arrs[mid] > key){
            return  rank(key, arrs, lo, mid - 1);
        }else {
            return mid;
        }
    }
    
    protected class Node<Item> {
    	Node<Item> node;
    	Item item;
    }

    public static int rank(int key, int[] arrs){
        int lo = 0;
        int hi = arrs.length - 1;
        
        while(lo <= hi) {
        	int mid = (lo + hi) / 2;
        	if (arrs[mid] < key){
                lo = mid + 1;
            }else if (arrs[mid] > key){
                hi = mid - 1;
            }else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(1.0/0);
    }
}
